←Select platform

GetValue<T>(DicomElement,bool,long,T,GetValueDelegate) Method

Summary

Returns the value of a DICOM element

Syntax
C#
VB
C++
public T GetValue<T>( 
   DicomElement element, 
   bool tree, 
   long tag, 
   T defaultValue, 
   GetValueDelegate getValueDelegate 
) 
Public Overloads Function GetValue(Of T)( _ 
   ByVal element As DicomElement, _ 
   ByVal tree As Boolean, _ 
   ByVal tag As Long, _ 
   ByVal defaultValue As T, _ 
   ByVal getValueDelegate As GetValueDelegate _ 
) As T 
public: 
T^ GetValuegeneric<typename T> 
(  
   DicomElement^ element, 
   bool tree, 
   int64 tag, 
   T^ defaultValue, 
   GetValueDelegate^ getValueDelegate 
)  

Parameters

element
an item in the data set.

tree
true to evaluate the Data Set as a tree; false to evaluate the Data Set as a list.

tag
tag of the item to find.

defaultValue
a value of type T that is returned if the actual value cannot be retrieved.

getValueDelegate
an optional delegate that converts that extracted data to any type.

Type Parameters

T
specifies the type of the value to return

Return Value

a value of type T that is the value of the DICOM element

Remarks

This method is used to retrieve a value from a DICOM element It is very flexible method that can be used to retrieve the value as any of the types below, regardless of the DicomVRType The caller specificies the type T of the value, and the value is converted to this type if possible. The generic type T Object can be any of the following:

The versions of GetValue that take a delegate can be used to retrieve ANY type, even if it is not native to DicomDataSet. The data is extracted from the value as a string passed to the provided method. The delegate is optional. Pass null if you do not want to use a delegate. Look at the example to see how to use the delegate. Below is a list of the overloads that take a delegate:

Some versions of GetValue return a reference to DicomDataSet, and return the value as an out parameter. These overloads are intended to be used by chaining them together, to make a very human readable code. See the part of the example that refers to a fluent interface to see how this is done. Below is a list of the overloads that return the type as an out parameter.

  • Generic GetValue(DicomElement,T,out T)
  • Generic GetValue(Int64,T,out T)

Some versions of GetValue have a parameter tag. For these versions, a search is done in the data set for an element that has this tag. Some of these overloads may also have element and tree parameters. If so, the search for tag starts at element. The search on the data set is performed as a list or tree depending on the tree parameter. For details on the element and tree parameters, see FindFirstElement

Other versions of this method do not have a tag parameter. In this case, a reference to the actual element is passed to the function, and the value of this element is returned.

All versions of this method take a defaultValue parameter. This is the value that is returned (or to which the out parameter is set) if the method cannot retrieve the actual value of the element, or if the element has no value. To see if this is the case, check the value of the property GetValueResult. For information on this method, see GetValue.

Example

This example will insert several elements into a DICOM data set, and then retrieve the values using delegates.

C#
VB
using Leadtools; 
using Leadtools.Dicom; 
 
///  
public class PersonName 
{ 
   private string[] _innerArray = new string[5] {string.Empty, string.Empty, string.Empty, string.Empty, 
                                               string.Empty }; 
 
   /// Access this person name instance as array. Index range is 
   /// bounded between 0 (family name) and 4 (name suffix). 
   public string this[int index] 
   { 
      set 
      { 
         if (value == null || value.Length < 64) 
            _innerArray[index] = value; 
         else 
            throw new DicomException("Length of new entry exceeds 64 characters."); 
      } 
 
      get { return _innerArray[index]; } 
   } 
 
   private const int _familyNameIndex = 0; 
   private const int _givenNameIndex = 1; 
   private const int _middleNameIndex = 2; 
   private const int _namePrefixIndex = 3; 
   private const int _nameSuffixIndex = 4; 
 
   /// Access person name part family name. 
   public string FamilyName 
   { 
      set 
      { 
         if (value == null || value.Length < 64) 
         { 
            _fullName = null; 
            _innerArray[_familyNameIndex] = value; 
         } 
         else 
            throw new DicomException("Length of family name exceeds 64 characters."); 
      } 
 
      get { return _innerArray[_familyNameIndex]; } 
   } 
 
   /// Access person name part given name. 
   public string GivenName 
   { 
      set 
      { 
         if (value == null || value.Length < 64) 
         { 
            _fullName = string.Empty; 
            _innerArray[_givenNameIndex] = value; 
         } 
         else 
            throw new DicomException("Length of family name exceeds 64 characters."); 
      } 
 
      get { return _innerArray[_givenNameIndex]; } 
   } 
 
   /// Access person name part middle name. 
   public string MiddleName 
   { 
      set 
      { 
         if (value == null || value.Length < 64) 
         { 
            _fullName = string.Empty; 
            _innerArray[_middleNameIndex] = value; 
         } 
         else 
            throw new DicomException("Length of family name exceeds 64 characters."); 
      } 
 
      get { return _innerArray[_middleNameIndex]; } 
   } 
 
   /// Access person name part name prefix. 
   public string NamePrefix 
   { 
      set 
      { 
         if (value == null || value.Length < 64) 
         { 
            _fullName = string.Empty; 
            _innerArray[_namePrefixIndex] = value; 
         } 
         else 
            throw new DicomException("Length of family name exceeds 64 characters."); 
      } 
 
      get { return _innerArray[_namePrefixIndex]; } 
   } 
 
   /// Access person name part name suffix. 
   public string NameSuffix 
   { 
      set 
      { 
         if (value == null || value.Length < 64) 
         { 
            _fullName = string.Empty; 
            _innerArray[_nameSuffixIndex] = value; 
         } 
         else 
            throw new DicomException("Length of family name exceeds 64 characters."); 
      } 
 
      get { return _innerArray[_nameSuffixIndex]; } 
   } 
 
   private string _fullName = string.Empty; 
   /// Access full person name string representation. According 
   /// to the DICOM standard "^" is used as separator of different 
   /// person name parts. 
   public string FullName 
   { 
      set 
      { 
         _fullName = value; 
         if (_fullName != null) 
         { 
            string[] s; 
            int i; 
 
            if (_fullName.Contains("^")) 
               s = _fullName.Split('^'); 
            else 
               s = _fullName.Split(' '); 
 
            for (i = 0; i < s.Length; i++) 
            { 
               if (s[i].Length < 64) 
               { 
                  if (i < _innerArray.Length) 
                     _innerArray[i] = s[i]; 
               } 
               else 
                  throw new DicomException("Length of family name exceeds 64 characters."); 
            } 
            for (int k = i; k < _innerArray.Length; k++) 
               _innerArray[k] = string.Empty; 
         } 
      } 
 
      get 
      { 
         if (_fullName == string.Empty) 
         { 
            _fullName = _innerArray[0]; 
            bool isNotNull = _fullName != string.Empty; 
            int i = 1; 
            while (isNotNull && i < _innerArray.Length) 
            { 
               isNotNull = _innerArray[i] != string.Empty; 
               if (isNotNull) 
                  _fullName += "^" + _innerArray[i]; 
               i++; 
            } 
         } 
         return _fullName; 
      } 
   } 
 
 
   /// Creates a new empty person name instance. 
   public PersonName() { } 
 
   /// Creates a new person name instance from specified full name. 
   /// All person name parts have to be separated by "^" according to 
   /// the DICOM standard. 
   public PersonName(string fullName) 
   { 
      FullName = fullName; 
   } 
 
   /// Creates a new person name instance from the different person name parts. 
   public PersonName(string familyName, string givenName, 
       string middleName, string namePrefix, string nameSuffix) 
   { 
      FamilyName = familyName; 
      GivenName = givenName; 
      MiddleName = middleName; 
      NamePrefix = namePrefix; 
      NameSuffix = nameSuffix; 
   } 
 
   /// Return this person name instance's. 
   public override string ToString() 
   { 
      return FullName; 
   } 
} 
 
void DumpPersonName(PersonName pn) 
{ 
   String sMsg = 
      string.Format("Family Name: {0}\nGiven Name: {1}\nMiddle Name: {2}\nName Prefix: {3}\nName Suffix: {4}", 
      pn.FamilyName, 
      pn.GivenName, 
      pn.MiddleName, 
      pn.NamePrefix, 
      pn.NameSuffix); 
   MessageBox.Show(sMsg); 
} 
 
private void DicomDataSet_GetValueWithDelegateExample() 
{ 
   // Create a DicomDataSet and add a PatientName 
   // Dicom Spec for Value Representation PN (Person Name) 
   // Elements are in this order: 
   // * family name complex 
   // * given name complex 
   // * middle name 
   // * name prefix 
   // * name suffix. 
   DicomDataSet ds = new DicomDataSet(); 
   ds.InsertElementAndSetValue(DicomTag.PatientName, "Smith^John^MiddleName^Mr.^III"); 
 
   // Get a PersonName value of an element by specifying a tag, and using a delegate 
   // Use this form when the type is not native to the dataset 
   // The data is extracted from the field as a string and passed to the provided method. 
   PersonName pn = null; 
 
   pn = ds.GetValue<PersonName>( 
      DicomTag.PatientName, 
      null, 
      delegate (string data) 
      { 
         PersonName t = new PersonName(data); 
         return t; 
      } 
      ); 
   DumpPersonName(pn); 
 
   // Another overload, specifying parent element 
   pn = ds.GetValue<PersonName>( 
      null, 
      true, 
      DicomTag.PatientName, 
      null, 
      delegate (string data) 
      { 
         PersonName t = new PersonName(data); 
         return t; 
      } 
      ); 
   DumpPersonName(pn); 
 
   // Another overload, this time passing in the DICOM element instead of a tag 
   DicomElement element = ds.FindFirstElement(null, DicomTag.PatientName, true); 
   pn = ds.GetValue<PersonName>( 
      element, 
      null, 
      delegate (string data) 
      { 
         PersonName t = new PersonName(data); 
         return t; 
      } 
      ); 
   DumpPersonName(pn); 
} 
Imports Leadtools 
Imports Leadtools.Dicom 
 
'''  
Public Class PersonName 
   Private _innerArray As String() = New String(4) {String.Empty, String.Empty, String.Empty, String.Empty, String.Empty} 
 
   ''' Access this person name instance as array. Index range is 
   ''' bounded between 0 (family name) and 4 (name suffix). 
   Default Public Property Item(ByVal index As Integer) As String 
      Set(ByVal value As String) 
         If value Is Nothing OrElse value.Length < 64 Then 
            _innerArray(index) = value 
         Else 
            Throw New DicomException("Length of new entry exceeds 64 characters.") 
         End If 
      End Set 
 
      Get 
         Return _innerArray(index) 
      End Get 
   End Property 
 
   Private Const _familyNameIndex As Integer = 0 
   Private Const _givenNameIndex As Integer = 1 
   Private Const _middleNameIndex As Integer = 2 
   Private Const _namePrefixIndex As Integer = 3 
   Private Const _nameSuffixIndex As Integer = 4 
 
   ''' Access person name part family name. 
   Public Property FamilyName() As String 
      Set(ByVal value As String) 
         If value Is Nothing OrElse value.Length < 64 Then 
            _fullName = Nothing 
            _innerArray(_familyNameIndex) = value 
         Else 
            Throw New DicomException("Length of family name exceeds 64 characters.") 
         End If 
      End Set 
 
      Get 
         Return _innerArray(_familyNameIndex) 
      End Get 
   End Property 
 
   ''' Access person name part given name. 
   Public Property GivenName() As String 
      Set(ByVal value As String) 
         If value Is Nothing OrElse value.Length < 64 Then 
            _fullName = String.Empty 
            _innerArray(_givenNameIndex) = value 
         Else 
            Throw New DicomException("Length of family name exceeds 64 characters.") 
         End If 
      End Set 
 
      Get 
         Return _innerArray(_givenNameIndex) 
      End Get 
   End Property 
 
   ''' Access person name part middle name. 
   Public Property MiddleName() As String 
      Set(ByVal value As String) 
         If value Is Nothing OrElse value.Length < 64 Then 
            _fullName = String.Empty 
            _innerArray(_middleNameIndex) = value 
         Else 
            Throw New DicomException("Length of family name exceeds 64 characters.") 
         End If 
      End Set 
 
      Get 
         Return _innerArray(_middleNameIndex) 
      End Get 
   End Property 
 
   ''' Access person name part name prefix. 
   Public Property NamePrefix() As String 
      Set(ByVal value As String) 
         If value Is Nothing OrElse value.Length < 64 Then 
            _fullName = String.Empty 
            _innerArray(_namePrefixIndex) = value 
         Else 
            Throw New DicomException("Length of family name exceeds 64 characters.") 
         End If 
      End Set 
 
      Get 
         Return _innerArray(_namePrefixIndex) 
      End Get 
   End Property 
 
   ''' Access person name part name suffix. 
   Public Property NameSuffix() As String 
      Set(ByVal value As String) 
         If value Is Nothing OrElse value.Length < 64 Then 
            _fullName = String.Empty 
            _innerArray(_nameSuffixIndex) = value 
         Else 
            Throw New DicomException("Length of family name exceeds 64 characters.") 
         End If 
      End Set 
 
      Get 
         Return _innerArray(_nameSuffixIndex) 
      End Get 
   End Property 
 
   Private _fullName As String = String.Empty 
   ''' Access full person name string representation. According 
   ''' to the DICOM standard "^" is used as separator of different 
   ''' person name parts. 
   Public Property FullName() As String 
      Set(ByVal value As String) 
         _fullName = value 
         If Not _fullName Is Nothing Then 
            Dim s As String() 
            Dim i As Integer 
 
            If _fullName.Contains("^") Then 
               s = _fullName.Split("^"c) 
            Else 
               s = _fullName.Split(" "c) 
            End If 
 
            i = 0 
            Do While i < s.Length 
               If s(i).Length < 64 Then 
                  If i < _innerArray.Length Then 
                     _innerArray(i) = s(i) 
                  End If 
               Else 
                  Throw New DicomException("Length of family name exceeds 64 characters.") 
               End If 
               i += 1 
            Loop 
            Dim k As Integer = i 
            Do While k < _innerArray.Length 
               _innerArray(k) = String.Empty 
               k += 1 
            Loop 
         End If 
      End Set 
 
      Get 
         If _fullName = String.Empty Then 
            _fullName = _innerArray(0) 
            Dim isNotNull As Boolean = _fullName <> String.Empty 
            Dim i As Integer = 1 
            Do While isNotNull AndAlso i < _innerArray.Length 
               isNotNull = _innerArray(i) <> String.Empty 
               If isNotNull Then 
                  _fullName &= "^" & _innerArray(i) 
               End If 
               i += 1 
            Loop 
         End If 
         Return _fullName 
      End Get 
   End Property 
 
 
   ''' Creates a new empty person name instance. 
   Public Sub New() 
   End Sub 
 
   ''' Creates a new person name instance from specified full name. 
   ''' All person name parts have to be separated by "^" according to 
   ''' the DICOM standard. 
   Public Sub New(ByVal fullNameIn As String) 
      FullName = fullNameIn 
   End Sub 
 
   ''' Creates a new person name instance from the different person name parts. 
   Public Sub New(ByVal familyNameIn As String, ByVal givenNameIn As String, ByVal middleNameIn As String, ByVal namePrefixIn As String, ByVal nameSuffixIn As String) 
      FamilyName = familyNameIn 
      GivenName = givenNameIn 
      MiddleName = middleNameIn 
      NamePrefix = namePrefixIn 
      NameSuffix = nameSuffixIn 
   End Sub 
 
   ''' Return this person name instance's. 
   Public Overrides Function ToString() As String 
      Return FullName 
   End Function 
End Class 
 
Private Sub DumpPersonName(ByVal pn As PersonName) 
   Dim sMsg As String = String.Format("Family Name: {0}" & Constants.vbLf & "Given Name: {1}" & Constants.vbLf & "Middle Name: {2}" & 
                                      Constants.vbLf & "Name Prefix: {3}" & Constants.vbLf & "Name Suffix: {4}", pn.FamilyName, pn.GivenName, 
                                      pn.MiddleName, pn.NamePrefix, pn.NameSuffix) 
   MessageBox.Show(sMsg) 
End Sub 
 
Public Function MyGetValueDelegate(ByVal s As String) As Object 
   Dim pn As PersonName = New PersonName(s) 
   MyGetValueDelegate = pn 
End Function 
 
Private Sub DicomDataSet_GetValueWithDelegateExample() 
   ' Create a DicomDataSet and add a PatientName 
   ' Dicom Spec for Value Representation PN (Person Name) 
   ' Elements are in this order: 
   ' * family name complex 
   ' * given name complex 
   ' * middle name 
   ' * name prefix 
   ' * name suffix. 
   Dim ds As DicomDataSet = New DicomDataSet() 
   ds.InsertElementAndSetValue(DicomTag.PatientName, "Smith^John^MiddleName^Mr.^III") 
 
   ' Get a PersonName value of an element by specifying a tag, and using a delegate 
   ' Use this form when the type is not native to the dataset 
   ' The data is extracted from the field as a string and passed to the provided method. 
   Dim pn As PersonName = Nothing 
 
 
   Dim myDelegate As GetValueDelegate 
   myDelegate = AddressOf MyGetValueDelegate 
 
   pn = ds.GetValue(Of PersonName)(DicomTag.PatientName, Nothing, myDelegate) 
   DumpPersonName(pn) 
 
   ' Another overload, specifying parent element 
   pn = ds.GetValue(Of PersonName)(Nothing, True, DicomTag.PatientName, Nothing, myDelegate) 
   DumpPersonName(pn) 
 
   ' Another overload, this time passing in the DICOM element instead of a tag 
   Dim element As DicomElement = ds.FindFirstElement(Nothing, DicomTag.PatientName, True) 
   pn = ds.GetValue(Of PersonName)(element, Nothing, myDelegate) 
   DumpPersonName(pn) 
End Sub 
c#[Silverlight C# Example] 
using Leadtools; 
using Leadtools.Dicom; 
using Leadtools.Examples; 
 
public class PersonName 
{ 
   private string[] _innerArray = new string[5] {string.Empty, string.Empty, string.Empty, string.Empty, 
                                               string.Empty }; 
 
   /// Access this person name instance as array. Index range is 
   /// bounded between 0 (family name) and 4 (name suffix). 
   public string this[int index] 
   { 
      set 
      { 
         if (value == null || value.Length < 64) 
            _innerArray[index] = value; 
         else 
            throw new DicomException("Length of new entry exceeds 64 characters."); 
      } 
 
      get { return _innerArray[index]; } 
   } 
 
   private const int _familyNameIndex = 0; 
   private const int _givenNameIndex = 1; 
   private const int _middleNameIndex = 2; 
   private const int _namePrefixIndex = 3; 
   private const int _nameSuffixIndex = 4; 
 
   /// Access person name part family name. 
   public string FamilyName 
   { 
      set 
      { 
         if (value == null || value.Length < 64) 
         { 
            _fullName = null; 
            _innerArray[_familyNameIndex] = value; 
         } 
         else 
            throw new DicomException("Length of family name exceeds 64 characters."); 
      } 
 
      get { return _innerArray[_familyNameIndex]; } 
   } 
 
   /// Access person name part given name. 
   public string GivenName 
   { 
      set 
      { 
         if (value == null || value.Length < 64) 
         { 
            _fullName = string.Empty; 
            _innerArray[_givenNameIndex] = value; 
         } 
         else 
            throw new DicomException("Length of family name exceeds 64 characters."); 
      } 
 
      get { return _innerArray[_givenNameIndex]; } 
   } 
 
   /// Access person name part middle name. 
   public string MiddleName 
   { 
      set 
      { 
         if (value == null || value.Length < 64) 
         { 
            _fullName = string.Empty; 
            _innerArray[_middleNameIndex] = value; 
         } 
         else 
            throw new DicomException("Length of family name exceeds 64 characters."); 
      } 
 
      get { return _innerArray[_middleNameIndex]; } 
   } 
 
   /// Access person name part name prefix. 
   public string NamePrefix 
   { 
      set 
      { 
         if (value == null || value.Length < 64) 
         { 
            _fullName = string.Empty; 
            _innerArray[_namePrefixIndex] = value; 
         } 
         else 
            throw new DicomException("Length of family name exceeds 64 characters."); 
      } 
 
      get { return _innerArray[_namePrefixIndex]; } 
   } 
 
   /// Access person name part name suffix. 
   public string NameSuffix 
   { 
      set 
      { 
         if (value == null || value.Length < 64) 
         { 
            _fullName = string.Empty; 
            _innerArray[_nameSuffixIndex] = value; 
         } 
         else 
            throw new DicomException("Length of family name exceeds 64 characters."); 
      } 
 
      get { return _innerArray[_nameSuffixIndex]; } 
   } 
 
   private string _fullName = string.Empty; 
   /// Access full person name string representation. According 
   /// to the DICOM standard "^" is used as separator of different 
   /// person name parts. 
   public string FullName 
   { 
      set 
      { 
         _fullName = value; 
         if (_fullName != null) 
         { 
            string[] s; 
            int i; 
 
            if (_fullName.Contains("^")) 
               s = _fullName.Split('^'); 
            else 
               s = _fullName.Split(' '); 
 
            for (i = 0; i < s.Length; i++) 
            { 
               if (s[i].Length < 64) 
               { 
                  if (i < _innerArray.Length) 
                     _innerArray[i] = s[i]; 
               } 
               else 
                  throw new DicomException("Length of family name exceeds 64 characters."); 
            } 
            for (int k = i; k < _innerArray.Length; k++) 
               _innerArray[k] = string.Empty; 
         } 
      } 
 
      get 
      { 
         if (_fullName == string.Empty) 
         { 
            _fullName = _innerArray[0]; 
            bool isNotNull = _fullName != string.Empty; 
            int i = 1; 
            while (isNotNull && i < _innerArray.Length) 
            { 
               isNotNull = _innerArray[i] != string.Empty; 
               if (isNotNull) 
                  _fullName += "^" + _innerArray[i]; 
               i++; 
            } 
         } 
         return _fullName; 
      } 
   } 
 
   /// Creates a new empty person name instance. 
   public PersonName() { } 
 
   /// Creates a new person name instance from specified full name. 
   /// All person name parts have to be separated by "^" according to 
   /// the DICOM standard. 
   public PersonName(string fullName) 
   { 
      FullName = fullName; 
   } 
 
   /// Creates a new person name instance from the different person name parts. 
   public PersonName(string familyName, string givenName, 
       string middleName, string namePrefix, string nameSuffix) 
   { 
      FamilyName = familyName; 
      GivenName = givenName; 
      MiddleName = middleName; 
      NamePrefix = namePrefix; 
      NameSuffix = nameSuffix; 
   } 
 
   /// Return this person name instance's. 
   public override string ToString() 
   { 
      return FullName; 
   } 
} 
 
void DumpPersonName(PersonName pn) 
{ 
   String sMsg = 
      string.Format("Family Name: {0}\nGiven Name: {1}\nMiddle Name: {2}\nName Prefix: {3}\nName Suffix: {4}", 
      pn.FamilyName, 
      pn.GivenName, 
      pn.MiddleName, 
      pn.NamePrefix, 
      pn.NameSuffix); 
   Debug.WriteLine(sMsg); 
} 
 
private void DicomDataSet_GetValueWithDelegateExample() 
{ 
   // Create a DicomDataSet and add a PatientName 
   // Dicom Spec for Value Representation PN (Person Name) 
   // Elements are in this order: 
   // * family name complex 
   // * given name complex 
   // * middle name 
   // * name prefix 
   // * name suffix. 
   DicomDataSet ds = new DicomDataSet(); 
   ds.InsertElementAndSetValue(DicomTag.PatientName, "Smith^John^MiddleName^Mr.^III"); 
 
   // Get a PersonName value of an element by specifying a tag, and using a delegate 
   // Use this form when the type is not native to the dataset 
   // The data is extracted from the field as a string and passed to the provided method. 
   PersonName pn = null; 
 
   pn = ds.GetValue<PersonName>( 
      DicomTag.PatientName, 
      null, 
      delegate (string data) 
      { 
         PersonName t = new PersonName(data); 
         return t; 
      } 
      ); 
   DumpPersonName(pn); 
 
   // Another overload, specifying parent element 
   pn = ds.GetValue<PersonName>( 
      null, 
      true, 
      DicomTag.PatientName, 
      null, 
      delegate (string data) 
      { 
         PersonName t = new PersonName(data); 
         return t; 
      } 
      ); 
   DumpPersonName(pn); 
 
   // Another overload, this time passing in the DICOM element instead of a tag 
   DicomElement element = ds.FindFirstElement(null, DicomTag.PatientName, true); 
   pn = ds.GetValue<PersonName>( 
      element, 
      null, 
      delegate (string data) 
      { 
         PersonName t = new PersonName(data); 
         return t; 
      } 
      ); 
   DumpPersonName(pn); 
} 
vb[Silverlight VB Example] 
Imports Leadtools 
Imports Leadtools.Dicom 
 
Public Class PersonName 
   Private _innerArray As String() = New String(4) {String.Empty, String.Empty, String.Empty, String.Empty, String.Empty} 
 
   ''' Access this person name instance as array. Index range is 
   ''' bounded between 0 (family name) and 4 (name suffix). 
   Default Public Property Item(ByVal index As Integer) As String 
      Set 
         If Value Is Nothing OrElse Value.Length < 64 Then 
            _innerArray(index) = Value 
         Else 
            Throw New DicomException("Length of new entry exceeds 64 characters.") 
         End If 
      End Set 
 
      Get 
         Return _innerArray(index) 
      End Get 
   End Property 
 
   Private Const _familyNameIndex As Integer = 0 
   Private Const _givenNameIndex As Integer = 1 
   Private Const _middleNameIndex As Integer = 2 
   Private Const _namePrefixIndex As Integer = 3 
   Private Const _nameSuffixIndex As Integer = 4 
 
   ''' Access person name part family name. 
   Public Property FamilyName() As String 
      Set 
         If Value Is Nothing OrElse Value.Length < 64 Then 
            _fullName = Nothing 
            _innerArray(_familyNameIndex) = Value 
         Else 
            Throw New DicomException("Length of family name exceeds 64 characters.") 
         End If 
      End Set 
 
      Get 
         Return _innerArray(_familyNameIndex) 
      End Get 
   End Property 
 
   ''' Access person name part given name. 
   Public Property GivenName() As String 
      Set 
         If Value Is Nothing OrElse Value.Length < 64 Then 
            _fullName = String.Empty 
            _innerArray(_givenNameIndex) = Value 
         Else 
            Throw New DicomException("Length of family name exceeds 64 characters.") 
         End If 
      End Set 
 
      Get 
         Return _innerArray(_givenNameIndex) 
      End Get 
   End Property 
 
   ''' Access person name part middle name. 
   Public Property MiddleName() As String 
      Set 
         If Value Is Nothing OrElse Value.Length < 64 Then 
            _fullName = String.Empty 
            _innerArray(_middleNameIndex) = Value 
         Else 
            Throw New DicomException("Length of family name exceeds 64 characters.") 
         End If 
      End Set 
 
      Get 
         Return _innerArray(_middleNameIndex) 
      End Get 
   End Property 
 
   ''' Access person name part name prefix. 
   Public Property NamePrefix() As String 
      Set 
         If Value Is Nothing OrElse Value.Length < 64 Then 
            _fullName = String.Empty 
            _innerArray(_namePrefixIndex) = Value 
         Else 
            Throw New DicomException("Length of family name exceeds 64 characters.") 
         End If 
      End Set 
 
      Get 
         Return _innerArray(_namePrefixIndex) 
      End Get 
   End Property 
 
   ''' Access person name part name suffix. 
   Public Property NameSuffix() As String 
      Set 
         If Value Is Nothing OrElse Value.Length < 64 Then 
            _fullName = String.Empty 
            _innerArray(_nameSuffixIndex) = Value 
         Else 
            Throw New DicomException("Length of family name exceeds 64 characters.") 
         End If 
      End Set 
 
      Get 
         Return _innerArray(_nameSuffixIndex) 
      End Get 
   End Property 
 
   Private _fullName As String = String.Empty 
   ''' Access full person name string representation. According 
   ''' to the DICOM standard "^" is used as separator of different 
   ''' person name parts. 
   Public Property FullName() As String 
      Set 
         _fullName = Value 
         If Not _fullName Is Nothing Then 
            Dim s As String() 
            Dim i As Integer 
 
            If _fullName.Contains("^") Then 
               s = _fullName.Split("^"c) 
            Else 
               s = _fullName.Split(" "c) 
            End If 
 
            i = 0 
            Do While i < s.Length 
               If s(i).Length < 64 Then 
                  If i < _innerArray.Length Then 
                     _innerArray(i) = s(i) 
                  End If 
               Else 
                  Throw New DicomException("Length of family name exceeds 64 characters.") 
               End If 
               i += 1 
            Loop 
            Dim k As Integer = i 
            Do While k < _innerArray.Length 
               _innerArray(k) = String.Empty 
               k += 1 
            Loop 
         End If 
      End Set 
 
      Get 
         If _fullName = String.Empty Then 
            _fullName = _innerArray(0) 
            Dim isNotNull As Boolean = _fullName <> String.Empty 
            Dim i As Integer = 1 
            Do While isNotNull AndAlso i < _innerArray.Length 
               isNotNull = _innerArray(i) <> String.Empty 
               If isNotNull Then 
                  _fullName &= "^" & _innerArray(i) 
               End If 
               i += 1 
            Loop 
         End If 
         Return _fullName 
      End Get 
   End Property 
 
   ''' Creates a new empty person name instance. 
   Public Sub New() 
   End Sub 
 
   '' Creates a new person name instance from specified full name. 
   '' All person name parts have to be separated by "^" according to 
   '' the DICOM standard. 
   Public Sub New(ByVal fullNameParam As String) 
      FullName = fullNameParam 
   End Sub 
 
   '' Creates a new person name instance from the different person name parts. 
   Public Sub New(ByVal familyNameParam As String, 
                  ByVal givenNameParam As String, 
                  ByVal middleNameParam As String, 
                  ByVal namePrefixParam As String, 
                  ByVal nameSuffixParam As String) 
      FamilyName = familyNameParam 
      GivenName = givenNameParam 
      MiddleName = middleNameParam 
      NamePrefix = namePrefixParam 
      NameSuffix = nameSuffixParam 
   End Sub 
 
   ''' Return this person name instance's. 
   Public Overrides Function ToString() As String 
      Return FullName 
   End Function 
End Class 
 
Private Sub DumpPersonName(ByVal pn As PersonName) 
   Dim sMsg As String = String.Format("Family Name: {0}" _ 
                                      & Constants.vbLf _ 
                                      & "Given Name: {1}" _ 
                                      & Constants.vbLf _ 
                                      & "Middle Name: {2}" _ 
                                      & Constants.vbLf _ 
                                      & "Name Prefix: {3}" _ 
                                      & Constants.vbLf _ 
                                      & "Name Suffix: {4}", 
                                      pn.FamilyName, 
                                      pn.GivenName, 
                                      pn.MiddleName, 
                                      pn.NamePrefix, 
                                      pn.NameSuffix) 
   Debug.WriteLine(sMsg) 
End Sub 
 
Private Function GetValueDelegate(ByVal data As String) As PersonName 
   Dim t As PersonName = New PersonName(data) 
   Return t 
End Function 
 
Private Sub DicomDataSet_GetValueWithDelegateExample() 
   ' Create a DicomDataSet and add a PatientName 
   ' Dicom Spec for Value Representation PN (Person Name) 
   ' Elements are in this order: 
   ' * family name complex 
   ' * given name complex 
   ' * middle name 
   ' * name prefix 
   ' * name suffix. 
   Dim ds As DicomDataSet = New DicomDataSet() 
   ds.InsertElementAndSetValue(DicomTag.PatientName, "Smith^John^MiddleName^Mr.^III") 
 
   ' Get a PersonName value of an element by specifying a tag, and using a delegate 
   ' Use this form when the type is not native to the dataset 
   ' The data is extracted from the field as a string and passed to the provided method. 
   Dim pn As PersonName = Nothing 
 
   pn = ds.GetValue(Of PersonName)(DicomTag.PatientName, Nothing, AddressOf GetValueDelegate) 
   DumpPersonName(pn) 
 
   ' Another overload, specifying parent element 
   pn = ds.GetValue(Of PersonName)(Nothing, True, DicomTag.PatientName, Nothing, AddressOf GetValueDelegate) 
   DumpPersonName(pn) 
 
   ' Another overload, this time passing in the DICOM element instead of a tag 
   Dim element As DicomElement = ds.FindFirstElement(Nothing, DicomTag.PatientName, True) 
   pn = ds.GetValue(Of PersonName)(element, Nothing, AddressOf GetValueDelegate) 
   DumpPersonName(pn) 
End Sub 

Requirements

Target Platforms

Help Version 20.0.2020.3.31
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2020 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Dicom Assembly